package pl.edu.agh.se.carsexpertsystem;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.swing.AbstractListModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.SpinnerNumberModel;

import pl.edu.agh.se.carsexpertsystem.engine.DroolsRunner;
import pl.edu.agh.se.carsexpertsystem.fact.BaldnessFact;
import pl.edu.agh.se.carsexpertsystem.fact.DifficultTerrainFact;
import pl.edu.agh.se.carsexpertsystem.fact.DistanceToWorkFact;
import pl.edu.agh.se.carsexpertsystem.fact.EarningsFact;
import pl.edu.agh.se.carsexpertsystem.fact.Fact;
import pl.edu.agh.se.carsexpertsystem.fact.FamilyFact;
import pl.edu.agh.se.carsexpertsystem.fact.RepresentativenessFact;
import pl.edu.agh.se.carsexpertsystem.fact.ShoppingFact;
import pl.edu.agh.se.carsexpertsystem.fact.SpeedFact;
import pl.edu.agh.se.carsexpertsystem.fact.TransportingGoodsFact;
import pl.edu.agh.se.carsexpertsystem.fact.ShoppingFact.ShoppingPreference;
import pl.edu.agh.se.carsexpertsystem.fact.WatchingGirlsFact;
import pl.edu.agh.se.carsexpertsystem.model.CarModel;
import pl.edu.agh.se.carsexpertsystem.model.ModelCreator;
import pl.edu.agh.se.carsexpertsystem.fact.Frequency;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import pl.edu.agh.se.carsexpertsystem.fact.DifficultTerrainFact.TerrainType;

public class Main extends JFrame {
    // filled in getResults();

    private List<CarModel> results = new ArrayList<CarModel>();

    public Main() {
        setResizable(false);
        GridBagLayout gridBagLayout = new GridBagLayout();
        gridBagLayout.columnWidths = new int[]{0, 0, 0, 0};
        gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        gridBagLayout.columnWeights = new double[]{1.0, 1.0, 0.0, Double.MIN_VALUE};
        gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
        getContentPane().setLayout(gridBagLayout);

        JLabel lblCzyDojezdaszSamochodem = new JLabel("Czy dojeżdżasz samochodem do pracy?");
        GridBagConstraints gbc_lblCzyDojedaszSamochodem = new GridBagConstraints();
        gbc_lblCzyDojedaszSamochodem.anchor = GridBagConstraints.EAST;
        gbc_lblCzyDojedaszSamochodem.insets = new Insets(0, 0, 5, 5);
        gbc_lblCzyDojedaszSamochodem.gridx = 0;
        gbc_lblCzyDojedaszSamochodem.gridy = 1;
        getContentPane().add(lblCzyDojezdaszSamochodem, gbc_lblCzyDojedaszSamochodem);

        final JCheckBox czyDojezdzaszCheckBox = new JCheckBox("");
        czyDojezdzaszCheckBox.setSelected(true);

        GridBagConstraints gbc_czyDojezdzaszSamochodemCheckbox = new GridBagConstraints();
        gbc_czyDojezdzaszSamochodemCheckbox.anchor = GridBagConstraints.WEST;
        gbc_czyDojezdzaszSamochodemCheckbox.insets = new Insets(0, 0, 5, 5);
        gbc_czyDojezdzaszSamochodemCheckbox.gridx = 1;
        gbc_czyDojezdzaszSamochodemCheckbox.gridy = 1;
        getContentPane().add(czyDojezdzaszCheckBox, gbc_czyDojezdzaszSamochodemCheckbox);

        JLabel lblIleKilometrwDziennie = new JLabel("Ile kilometrów dziennie?");
        GridBagConstraints gbc_lblIleKilometrwDziennie = new GridBagConstraints();
        gbc_lblIleKilometrwDziennie.anchor = GridBagConstraints.EAST;
        gbc_lblIleKilometrwDziennie.insets = new Insets(0, 0, 5, 5);
        gbc_lblIleKilometrwDziennie.gridx = 0;
        gbc_lblIleKilometrwDziennie.gridy = 2;
        getContentPane().add(lblIleKilometrwDziennie, gbc_lblIleKilometrwDziennie);

        final JSpinner ileKilometrowSpinner = new JSpinner();
        ileKilometrowSpinner.setModel(new SpinnerNumberModel(5, 0, 100, 1));
        GridBagConstraints gbc_ileKilometrowSpinner = new GridBagConstraints();
        gbc_ileKilometrowSpinner.anchor = GridBagConstraints.WEST;
        gbc_ileKilometrowSpinner.insets = new Insets(0, 0, 5, 5);
        gbc_ileKilometrowSpinner.gridx = 1;
        gbc_ileKilometrowSpinner.gridy = 2;
        getContentPane().add(ileKilometrowSpinner, gbc_ileKilometrowSpinner);

        JLabel label1 = new JLabel("> 0");
        GridBagConstraints gbc_label1 = new GridBagConstraints();
        gbc_label1.anchor = GridBagConstraints.WEST;
        gbc_label1.insets = new Insets(0, 0, 5, 0);
        gbc_label1.gridx = 2;
        gbc_label1.gridy = 2;
        getContentPane().add(label1, gbc_label1);

        JLabel lblIleZarabiasz = new JLabel("Ile zarabiasz?");
        GridBagConstraints gbc_lblIleZarabiasz = new GridBagConstraints();
        gbc_lblIleZarabiasz.anchor = GridBagConstraints.EAST;
        gbc_lblIleZarabiasz.insets = new Insets(0, 0, 5, 5);
        gbc_lblIleZarabiasz.gridx = 0;
        gbc_lblIleZarabiasz.gridy = 3;
        getContentPane().add(lblIleZarabiasz, gbc_lblIleZarabiasz);

        final JSpinner ileZarabiasz = new JSpinner();
        ileZarabiasz.setModel(new SpinnerNumberModel(2000, 0, 1000000, 100));
        GridBagConstraints gbc_spinner_1 = new GridBagConstraints();
        gbc_spinner_1.anchor = GridBagConstraints.WEST;
        gbc_spinner_1.insets = new Insets(0, 0, 5, 5);
        gbc_spinner_1.gridx = 1;
        gbc_spinner_1.gridy = 3;
        getContentPane().add(ileZarabiasz, gbc_spinner_1);

        JLabel label2 = new JLabel("> 0");
        GridBagConstraints gbc_label2 = new GridBagConstraints();
        gbc_label2.anchor = GridBagConstraints.WEST;
        gbc_label2.insets = new Insets(0, 0, 5, 0);
        gbc_label2.gridx = 2;
        gbc_label2.gridy = 3;
        getContentPane().add(label2, gbc_label2);

        JLabel lblIleMaszOsb = new JLabel("Ile masz osób w rodzinie?");
        GridBagConstraints gbc_lblIleMaszOsb = new GridBagConstraints();
        gbc_lblIleMaszOsb.anchor = GridBagConstraints.EAST;
        gbc_lblIleMaszOsb.insets = new Insets(0, 0, 5, 5);
        gbc_lblIleMaszOsb.gridx = 0;
        gbc_lblIleMaszOsb.gridy = 4;
        getContentPane().add(lblIleMaszOsb, gbc_lblIleMaszOsb);

        final JSpinner ileOsobSpinner = new JSpinner();
        ileOsobSpinner.setModel(new SpinnerNumberModel(new Integer(1), new Integer(1), null, new Integer(1)));
        GridBagConstraints gbc_ileOsobSpinner;
        gbc_ileOsobSpinner = new GridBagConstraints();
        gbc_ileOsobSpinner.anchor = GridBagConstraints.WEST;
        gbc_ileOsobSpinner.insets = new Insets(0, 0, 5, 5);
        gbc_ileOsobSpinner.gridx = 1;
        gbc_ileOsobSpinner.gridy = 4;
        getContentPane().add(ileOsobSpinner, gbc_ileOsobSpinner);

        JLabel label3 = new JLabel("> 0");
        GridBagConstraints gbc_label3 = new GridBagConstraints();
        gbc_label3.anchor = GridBagConstraints.WEST;
        gbc_label3.insets = new Insets(0, 0, 5, 0);
        gbc_label3.gridx = 2;
        gbc_label3.gridy = 4;
        getContentPane().add(label3, gbc_label3);

        JLabel lblJakCzstoRobisz = new JLabel("Jak często robisz zakupy?");
        GridBagConstraints gbc_lblJakCzstoRobisz = new GridBagConstraints();
        gbc_lblJakCzstoRobisz.anchor = GridBagConstraints.EAST;
        gbc_lblJakCzstoRobisz.insets = new Insets(0, 0, 5, 5);
        gbc_lblJakCzstoRobisz.gridx = 0;
        gbc_lblJakCzstoRobisz.gridy = 5;
        getContentPane().add(lblJakCzstoRobisz, gbc_lblJakCzstoRobisz);

        final JComboBox<ShoppingPreference> jakCzestoZakupyCombo = new JComboBox<ShoppingPreference>();
        jakCzestoZakupyCombo.setModel(new DefaultComboBoxModel<ShoppingPreference>(ShoppingPreference.values()));
        GridBagConstraints gbc_jakCzestoZakupyCombo = new GridBagConstraints();
        gbc_jakCzestoZakupyCombo.insets = new Insets(0, 0, 5, 5);
        gbc_jakCzestoZakupyCombo.fill = GridBagConstraints.HORIZONTAL;
        gbc_jakCzestoZakupyCombo.gridx = 1;
        gbc_jakCzestoZakupyCombo.gridy = 5;
        getContentPane().add(jakCzestoZakupyCombo, gbc_jakCzestoZakupyCombo);

        JLabel lblCzyOgldaszSi = new JLabel("Jak często oglądasz się za dziewczynami?");
        GridBagConstraints gbc_lblCzyOgldaszSi = new GridBagConstraints();
        gbc_lblCzyOgldaszSi.anchor = GridBagConstraints.EAST;
        gbc_lblCzyOgldaszSi.insets = new Insets(0, 0, 5, 5);
        gbc_lblCzyOgldaszSi.gridx = 0;
        gbc_lblCzyOgldaszSi.gridy = 6;
        getContentPane().add(lblCzyOgldaszSi, gbc_lblCzyOgldaszSi);


        final JSpinner jakCzestoOgladaszSieZaDziewczynamiSpinner = new JSpinner();
        jakCzestoOgladaszSieZaDziewczynamiSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 1.0, 0.1));
        GridBagConstraints gbc_jakCzestoOgladaszSieZaDziewczynamiSpinner = new GridBagConstraints();
        gbc_jakCzestoOgladaszSieZaDziewczynamiSpinner.anchor = GridBagConstraints.WEST;
        gbc_jakCzestoOgladaszSieZaDziewczynamiSpinner.insets = new Insets(0, 0, 5, 5);
        gbc_jakCzestoOgladaszSieZaDziewczynamiSpinner.gridx = 1;
        gbc_jakCzestoOgladaszSieZaDziewczynamiSpinner.gridy = 6;
        getContentPane().add(jakCzestoOgladaszSieZaDziewczynamiSpinner, gbc_jakCzestoOgladaszSieZaDziewczynamiSpinner);

        JLabel label4 = new JLabel("0-1");
        GridBagConstraints gbc_label4 = new GridBagConstraints();
        gbc_label4.anchor = GridBagConstraints.WEST;
        gbc_label4.insets = new Insets(0, 0, 5, 0);
        gbc_label4.gridx = 2;
        gbc_label4.gridy = 6;
        getContentPane().add(label4, gbc_label4);

        JLabel lblJakBardzoysy = new JLabel("Jak bardzo łysy jesteś? (%)");
        GridBagConstraints gbc_lblJakBardzoysy = new GridBagConstraints();
        gbc_lblJakBardzoysy.anchor = GridBagConstraints.EAST;
        gbc_lblJakBardzoysy.insets = new Insets(0, 0, 5, 5);
        gbc_lblJakBardzoysy.gridx = 0;
        gbc_lblJakBardzoysy.gridy = 7;
        getContentPane().add(lblJakBardzoysy, gbc_lblJakBardzoysy);

        final JSpinner jakLysySpinner = new JSpinner();
        jakLysySpinner.setModel(new SpinnerNumberModel(0, 0, 100, 1));
        GridBagConstraints gbc_jakLysySpinner = new GridBagConstraints();
        gbc_jakLysySpinner.anchor = GridBagConstraints.WEST;
        gbc_jakLysySpinner.insets = new Insets(0, 0, 5, 5);
        gbc_jakLysySpinner.gridx = 1;
        gbc_jakLysySpinner.gridy = 7;
        getContentPane().add(jakLysySpinner, gbc_jakLysySpinner);

        JLabel label5 = new JLabel("0-100");
        GridBagConstraints gbc_label5 = new GridBagConstraints();
        gbc_label5.anchor = GridBagConstraints.WEST;
        gbc_label5.insets = new Insets(0, 0, 5, 0);
        gbc_label5.gridx = 2;
        gbc_label5.gridy = 7;
        getContentPane().add(label5, gbc_label5);

        JLabel lblJakBardzoReprezentacyjny = new JLabel("Jak bardzo reprezentacyjny samochód?");
        GridBagConstraints gbc_lblJakBardzoReprezentacyjny = new GridBagConstraints();
        gbc_lblJakBardzoReprezentacyjny.anchor = GridBagConstraints.EAST;
        gbc_lblJakBardzoReprezentacyjny.insets = new Insets(0, 0, 5, 5);
        gbc_lblJakBardzoReprezentacyjny.gridx = 0;
        gbc_lblJakBardzoReprezentacyjny.gridy = 8;
        getContentPane().add(lblJakBardzoReprezentacyjny, gbc_lblJakBardzoReprezentacyjny);

        final JSpinner jakReprezentacyjnySpinner = new JSpinner();
        jakReprezentacyjnySpinner.setModel(new SpinnerNumberModel(500000000, 0, 1000000000, 1));
        GridBagConstraints gbc_jakReprezentacyjnySpinner = new GridBagConstraints();
        gbc_jakReprezentacyjnySpinner.anchor = GridBagConstraints.WEST;
        gbc_jakReprezentacyjnySpinner.insets = new Insets(0, 0, 5, 5);
        gbc_jakReprezentacyjnySpinner.gridx = 1;
        gbc_jakReprezentacyjnySpinner.gridy = 8;
        getContentPane().add(jakReprezentacyjnySpinner, gbc_jakReprezentacyjnySpinner);

        JLabel label6 = new JLabel("0-1000000000");
        GridBagConstraints gbc_label6 = new GridBagConstraints();
        gbc_label6.anchor = GridBagConstraints.WEST;
        gbc_label6.insets = new Insets(0, 0, 5, 0);
        gbc_label6.gridx = 2;
        gbc_label6.gridy = 8;
        getContentPane().add(label6, gbc_label6);

        JLabel lblZJakPrdkoci = new JLabel("Z jaką prędkością lubisz jeździć?");
        GridBagConstraints gbc_lblZJakPrdkoci = new GridBagConstraints();
        gbc_lblZJakPrdkoci.insets = new Insets(0, 0, 5, 5);
        gbc_lblZJakPrdkoci.gridx = 0;
        gbc_lblZJakPrdkoci.gridy = 9;
        getContentPane().add(lblZJakPrdkoci, gbc_lblZJakPrdkoci);

        final JSpinner jakaPredkoscSpinner = new JSpinner();
        jakaPredkoscSpinner.setModel(new SpinnerNumberModel(90, 0, 300, 10));
        GridBagConstraints gbc_jakaPredkoscSpinner = new GridBagConstraints();
        gbc_jakaPredkoscSpinner.anchor = GridBagConstraints.WEST;
        gbc_jakaPredkoscSpinner.insets = new Insets(0, 0, 5, 5);
        gbc_jakaPredkoscSpinner.gridx = 1;
        gbc_jakaPredkoscSpinner.gridy = 9;
        getContentPane().add(jakaPredkoscSpinner, gbc_jakaPredkoscSpinner);

        JLabel label7 = new JLabel("0-300");
        GridBagConstraints gbc_label7 = new GridBagConstraints();
        gbc_label7.anchor = GridBagConstraints.WEST;
        gbc_label7.insets = new Insets(0, 0, 5, 0);
        gbc_label7.gridx = 2;
        gbc_label7.gridy = 9;
        getContentPane().add(label7, gbc_label7);

        JLabel lblJakCzstoWozisz = new JLabel("Jak często wozisz towar?");
        GridBagConstraints gbc_lblJakCzstoWozisz = new GridBagConstraints();
        gbc_lblJakCzstoWozisz.anchor = GridBagConstraints.EAST;
        gbc_lblJakCzstoWozisz.insets = new Insets(0, 0, 5, 5);
        gbc_lblJakCzstoWozisz.gridx = 0;
        gbc_lblJakCzstoWozisz.gridy = 10;
        getContentPane().add(lblJakCzstoWozisz, gbc_lblJakCzstoWozisz);

        JScrollPane resultListScrollPane = new JScrollPane();
        resultListScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        GridBagConstraints gbc_resultListScrollPane = new GridBagConstraints();
        gbc_resultListScrollPane.gridheight = 9;
        gbc_resultListScrollPane.insets = new Insets(0, 0, 0, 5);
        gbc_resultListScrollPane.fill = GridBagConstraints.BOTH;
        gbc_resultListScrollPane.gridx = 0;
        gbc_resultListScrollPane.gridy = 13;
        getContentPane().add(resultListScrollPane, gbc_resultListScrollPane);

        final JList<String> resultList = new JList<String>();

        resultList.setVisibleRowCount(5);
        @SuppressWarnings("serial")
        ListModel<String> resultListModel = new AbstractListModel<String>() {

            public int getSize() {
                return results.size();
            }

            public String getElementAt(int index) {
                CarModel car = results.get(index);
                return car.getManufacturer().getName() + " " + car.getName();
            }
        };

        resultList.setModel(resultListModel);
        resultList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        resultListScrollPane.setViewportView(resultList);

        final JComboBox<Frequency> jakCzestoWoziszComboBox = new JComboBox<Frequency>();
        jakCzestoWoziszComboBox.setModel(new DefaultComboBoxModel<Frequency>(Frequency.values()));
        GridBagConstraints gbc_jakCzestoWoziszComboBox = new GridBagConstraints();
        gbc_jakCzestoWoziszComboBox.insets = new Insets(0, 0, 5, 5);
        gbc_jakCzestoWoziszComboBox.fill = GridBagConstraints.HORIZONTAL;
        gbc_jakCzestoWoziszComboBox.gridx = 1;
        gbc_jakCzestoWoziszComboBox.gridy = 10;
        getContentPane().add(jakCzestoWoziszComboBox, gbc_jakCzestoWoziszComboBox);

        JLabel lblPoJakimTerenie = new JLabel("Po jakim terenie jeździsz?");
        GridBagConstraints gbc_lblPoJakimTerenie = new GridBagConstraints();
        gbc_lblPoJakimTerenie.anchor = GridBagConstraints.EAST;
        gbc_lblPoJakimTerenie.insets = new Insets(0, 0, 5, 5);
        gbc_lblPoJakimTerenie.gridx = 0;
        gbc_lblPoJakimTerenie.gridy = 11;
        getContentPane().add(lblPoJakimTerenie, gbc_lblPoJakimTerenie);

        final JComboBox<TerrainType> jakiTerenComboBox = new JComboBox<TerrainType>();
        jakiTerenComboBox.setModel(new DefaultComboBoxModel<TerrainType>(TerrainType.values()));
        GridBagConstraints gbc_jakiTerenComboBox = new GridBagConstraints();
        gbc_jakiTerenComboBox.insets = new Insets(0, 0, 5, 5);
        gbc_jakiTerenComboBox.fill = GridBagConstraints.HORIZONTAL;
        gbc_jakiTerenComboBox.gridx = 1;
        gbc_jakiTerenComboBox.gridy = 11;
        getContentPane().add(jakiTerenComboBox, gbc_jakiTerenComboBox);

        JButton btnUruchomEkspertyz = new JButton("Uruchom ekspertyzę");
        GridBagConstraints gbc_btnUruchomEkspertyz = new GridBagConstraints();
        gbc_btnUruchomEkspertyz.insets = new Insets(0, 0, 5, 5);
        gbc_btnUruchomEkspertyz.gridx = 1;
        gbc_btnUruchomEkspertyz.gridy = 12;
        getContentPane().add(btnUruchomEkspertyz, gbc_btnUruchomEkspertyz);


        JLabel label_17 = new JLabel("Cena [zł]:");
        GridBagConstraints gbc_label_17 = new GridBagConstraints();
        gbc_label_17.anchor = GridBagConstraints.EAST;
        gbc_label_17.insets = new Insets(0, 0, 5, 5);
        gbc_label_17.gridx = 1;
        gbc_label_17.gridy = 13;
        getContentPane().add(label_17, gbc_label_17);

        final JLabel lblCena = new JLabel("-");
        GridBagConstraints gbc_lblCena = new GridBagConstraints();
        gbc_lblCena.insets = new Insets(0, 0, 5, 0);
        gbc_lblCena.gridx = 2;
        gbc_lblCena.gridy = 13;
        getContentPane().add(lblCena, gbc_lblCena);

        final JLabel lblBaganik = new JLabel("Bagażnik [l]:");
        GridBagConstraints gbc_lblBaganik = new GridBagConstraints();
        gbc_lblBaganik.anchor = GridBagConstraints.EAST;
        gbc_lblBaganik.insets = new Insets(0, 0, 5, 5);
        gbc_lblBaganik.gridx = 1;
        gbc_lblBaganik.gridy = 15;
        getContentPane().add(lblBaganik, gbc_lblBaganik);

        final JLabel lblBagaznik = new JLabel("-");
        GridBagConstraints gbc_lblBagaznik = new GridBagConstraints();
        gbc_lblBagaznik.insets = new Insets(0, 0, 5, 0);
        gbc_lblBagaznik.gridx = 2;
        gbc_lblBagaznik.gridy = 15;
        getContentPane().add(lblBagaznik, gbc_lblBagaznik);

        final JLabel lblIloSiedze = new JLabel("Ilość siedzeń:");
        GridBagConstraints gbc_lblIloSiedze = new GridBagConstraints();
        gbc_lblIloSiedze.anchor = GridBagConstraints.EAST;
        gbc_lblIloSiedze.insets = new Insets(0, 0, 5, 5);
        gbc_lblIloSiedze.gridx = 1;
        gbc_lblIloSiedze.gridy = 16;
        getContentPane().add(lblIloSiedze, gbc_lblIloSiedze);

        final JLabel lblIloscSiedzen = new JLabel("-");
        GridBagConstraints gbc_lblIloscSiedzen = new GridBagConstraints();
        gbc_lblIloscSiedzen.insets = new Insets(0, 0, 5, 0);
        gbc_lblIloscSiedzen.gridx = 2;
        gbc_lblIloscSiedzen.gridy = 16;
        getContentPane().add(lblIloscSiedzen, gbc_lblIloscSiedzen);

        final JLabel lblZuyciePaliwa = new JLabel("Zużycie paliwa [l / 100 km]:");
        GridBagConstraints gbc_lblZuyciePaliwa = new GridBagConstraints();
        gbc_lblZuyciePaliwa.anchor = GridBagConstraints.EAST;
        gbc_lblZuyciePaliwa.insets = new Insets(0, 0, 5, 5);
        gbc_lblZuyciePaliwa.gridx = 1;
        gbc_lblZuyciePaliwa.gridy = 17;
        getContentPane().add(lblZuyciePaliwa, gbc_lblZuyciePaliwa);

        final JLabel lblZuzyciePaliwa = new JLabel("-");
        GridBagConstraints gbc_lblZuzyciePaliwa = new GridBagConstraints();
        gbc_lblZuzyciePaliwa.insets = new Insets(0, 0, 5, 0);
        gbc_lblZuzyciePaliwa.gridx = 2;
        gbc_lblZuzyciePaliwa.gridy = 17;
        getContentPane().add(lblZuzyciePaliwa, gbc_lblZuzyciePaliwa);

        final JLabel label_18 = new JLabel("Moc [KM]:");
        GridBagConstraints gbc_label_18 = new GridBagConstraints();
        gbc_label_18.anchor = GridBagConstraints.EAST;
        gbc_label_18.insets = new Insets(0, 0, 5, 5);
        gbc_label_18.gridx = 1;
        gbc_label_18.gridy = 18;
        getContentPane().add(label_18, gbc_label_18);

        final JLabel lblMoc = new JLabel("-");
        GridBagConstraints gbc_lblMoc = new GridBagConstraints();
        gbc_lblMoc.insets = new Insets(0, 0, 5, 0);
        gbc_lblMoc.gridx = 2;
        gbc_lblMoc.gridy = 18;
        getContentPane().add(lblMoc, gbc_lblMoc);

        final JLabel label_19 = new JLabel("Segment:");
        GridBagConstraints gbc_label_19 = new GridBagConstraints();
        gbc_label_19.anchor = GridBagConstraints.EAST;
        gbc_label_19.insets = new Insets(0, 0, 5, 5);
        gbc_label_19.gridx = 1;
        gbc_label_19.gridy = 19;
        getContentPane().add(label_19, gbc_label_19);

        final JLabel lblSegment = new JLabel("-");
        GridBagConstraints gbc_lblSegment = new GridBagConstraints();
        gbc_lblSegment.anchor = GridBagConstraints.NORTH;
        gbc_lblSegment.insets = new Insets(0, 0, 5, 0);
        gbc_lblSegment.gridx = 2;
        gbc_lblSegment.gridy = 19;
        getContentPane().add(lblSegment, gbc_lblSegment);

        final JLabel lblNapdx = new JLabel("Napęd 4x4:");
        GridBagConstraints gbc_lblNapdx = new GridBagConstraints();
        gbc_lblNapdx.anchor = GridBagConstraints.EAST;
        gbc_lblNapdx.insets = new Insets(0, 0, 5, 5);
        gbc_lblNapdx.gridx = 1;
        gbc_lblNapdx.gridy = 20;
        getContentPane().add(lblNapdx, gbc_lblNapdx);

        final JLabel lblNaped4x4 = new JLabel("-");
        GridBagConstraints gbc_lblNaped4x4 = new GridBagConstraints();
        gbc_lblNaped4x4.insets = new Insets(0, 0, 5, 0);
        gbc_lblNaped4x4.gridx = 2;
        gbc_lblNaped4x4.gridy = 20;
        getContentPane().add(lblNaped4x4, gbc_lblNaped4x4);

        czyDojezdzaszCheckBox.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseReleased(MouseEvent arg0) {
                ileKilometrowSpinner.setEnabled(czyDojezdzaszCheckBox.isSelected());
            }
        });

        btnUruchomEkspertyz.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                lblCena.setText("-");
                lblBagaznik.setText("-");
                lblIloscSiedzen.setText("-");
                lblZuzyciePaliwa.setText("-");
                lblMoc.setText("-");
                lblSegment.setText("-");
                lblNaped4x4.setText("-");

                List<Fact> facts = new LinkedList<Fact>();

                DistanceToWorkFact dtwFact = new DistanceToWorkFact();
                dtwFact.setDoesNotUseCarForThatPurpose(!czyDojezdzaszCheckBox.isSelected());
                dtwFact.setDistanceInKm((Integer) ileKilometrowSpinner.getValue());
                facts.add(dtwFact);

                EarningsFact ef = new EarningsFact();
                ef.setEarnings((Integer) ileZarabiasz.getValue());
                facts.add(ef);

                FamilyFact ff = new FamilyFact();
                ff.setNumberOfFamilyMembers((Integer) ileOsobSpinner.getValue());
                facts.add(ff);

                ShoppingFact sf = new ShoppingFact();
                sf.setShoppingPreference((ShoppingPreference) jakCzestoZakupyCombo.getSelectedItem());
                facts.add(sf);

                WatchingGirlsFact wgfFact = new WatchingGirlsFact();
                wgfFact.setWatchingGirlsGoingByFrequencyInGirlsWatchedToAllGirlsPassedBy(
                        (Double) jakCzestoOgladaszSieZaDziewczynamiSpinner.getValue());
                facts.add(wgfFact);

                BaldnessFact bFact = new BaldnessFact();
                bFact.setBaldnessPercent((Integer) jakLysySpinner.getValue());
                facts.add(bFact);

                RepresentativenessFact rFact = new RepresentativenessFact();
                rFact.setCarRepresenativenessOnScaleOfZeroToOneBillion((Integer) jakReprezentacyjnySpinner.getValue());
                facts.add(rFact);

                SpeedFact sFact = new SpeedFact();
                sFact.setPerfectSpeedForCruising((Integer) jakaPredkoscSpinner.getValue());
                facts.add(sFact);

                TransportingGoodsFact tgFact = new TransportingGoodsFact();
                tgFact.setFrequency((Frequency) jakCzestoWoziszComboBox.getSelectedItem());
                facts.add(tgFact);

                DifficultTerrainFact dtFact = new DifficultTerrainFact();
                dtFact.setMostFrequentlyEncounteredTerrainType((TerrainType) jakiTerenComboBox.getSelectedItem());
                facts.add(dtFact);

                // run drools
                Map<String, CarModel> conclusions = ModelCreator.getCars();

                DroolsRunner runner = new DroolsRunner(conclusions, facts);
                results = runner.getResults();

                resultList.updateUI();
                resultList.clearSelection();
            }
        });

        resultList.addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent arg0) {
                int index = resultList.getSelectedIndex();
                if (index != -1) {
                    CarModel model = results.get(resultList.getSelectedIndex());
                    lblCena.setText(String.valueOf(model.getPrice()));
                    lblBagaznik.setText(String.valueOf(model.getBootSize()));
                    lblIloscSiedzen.setText(String.valueOf(model.getSeatCount()));
                    lblZuzyciePaliwa.setText(String.valueOf(model.getFuelConsumption()));
                    lblMoc.setText(String.valueOf(model.getPower()));
                    lblSegment.setText(model.getCarSegment().toString());
                    lblNaped4x4.setText(String.valueOf(model.isFourWheelDrive()));
                }
            }
        });
    }
    private static final long serialVersionUID = -6087338145300023649L;

    public static void main(String[] args) {
        Main frame = new Main();
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setTitle("Wybór samochodu");
        frame.setSize(600, 500);
        frame.setVisible(true);
    }
}